package com.tsingsoft.wslogs.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
 * ========================
 *
 * @author bask
 * @Description: TODO
 * @date : 2021/1/8 16:57
 * Version: 1.0
 * ========================
 */
@Configuration
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Value("${my.ws_host:localhost}")
    private String wsHost;

    @Value("${server.port:9999}")
    private String port;

    public WebSocketConfig() {
    }

    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint(new String[]{"/websocket"}).setAllowedOrigins(new String[]{"http://"+wsHost+":"+port}).withSockJS();
    }
}
